package com.hwg.emp.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.hwg.emp.common.util.DBUtil;
import com.hwg.emp.dao.RoleDAO;
import com.hwg.emp.model.RoleMD;
import com.hwg.emp.model.UserMD;

public class RoleDAOImpl implements RoleDAO {

	@Override
	public int insert(RoleMD t) throws Exception {
		return 0;
		
	}

	@Override
	public int delete(String uk, String ukValue) throws Exception {
		return 0;
		
	}

	@Override
	public int update(RoleMD t) throws Exception {
		return 0;
		
	}

	@Override
	public RoleMD select(String uk, String ukValue) throws Exception {
		return null;
	}
	
	/**
	 * 拼凑结果集
	 * @param rs 传入一个结果集
	 * @return 用户对象
	 * @throws SQLException
	 */
	private RoleMD result2md(ResultSet rs)throws SQLException{
		RoleMD md=new RoleMD();
		md.setCode(rs.getString("code"));
		md.setId(rs.getString("id"));
		md.setName(rs.getString("name"));
		md.setRemark(rs.getString("remark"));
		md.setStatus(rs.getInt("status"));
		return md;
	}

	@Override
	public boolean exist(String uk, String ukValue) throws Exception {
		return false;
	}

	@Override
	public RoleMD selectRoleByEmpId(String id) throws Exception {
		Connection con=DBUtil.getConnection();
		StringBuilder sql=new StringBuilder();
		sql.append("select * from rel_role_employee re ")
		.append("join sys_role r on re.role_id=r.id ")
		.append("where re.emp_id=?");
		PreparedStatement ps=con.prepareStatement(sql.toString());
		ps.setObject(1, id);
		ResultSet rs=ps.executeQuery();
		if(rs.next()){
			return result2md(rs);
		}
		return null;
	}

}
